// 云函数入口文件
const cloud = require('wx-server-sdk')
let  del  = require("./del/index");
let  add  = require("./add/index");

cloud.init({env:"cloud1-7g87ggqn0c86123d"})
const db = cloud.database(); //引入数据库

// 云函数入口函数
exports.main = async (event, context) => {
    const wxContext = cloud.getWXContext();
    let {
        OPENID: _openid
    } = wxContext;

    switch (event.type) {
        case  "del":
            return await del.main(event,context);
        case  "add":
            return    await   add.main(event,context);  
        default://默认做查询
            return await db.collection("userinfo").where({
                _openid
            }).get(); //支持Promise
    }

 
    // return {
    //     event,
    //     openid: wxContext.OPENID,
    //     appid: wxContext.APPID,
    //     unionid: wxContext.UNIONID,
    // }
}